<style>
  .warna_target{
    background-color: #e9c2c2;
  }
  .warna_harian{
    background-color: #ccf5f2;
  }
</style>
<script>
  function get_dot(asli, koma){
    asli = asli.toFixed(0);
    asli = asli.toString();
    var asli_temp = asli.split(".");
    var string = asli_temp[0];
    var string_hasil = "";
    
    var tanda = 0;
    var kl = string.length % 3;
    if(kl == 0)
      kl = 3;
    for(i = 0 ; i < string.length ; i++){
      if(tanda == 3 || i == kl){
        string_hasil = string_hasil + ".";
        tanda = 0;
        kl = 0;
      }
      string_hasil = string_hasil + string[i];
      tanda++;
    }
//    if(koma == true){
      if(!asli_temp[1])
        asli_temp[1] = '';
      
      return string_hasil;
//    }
//    else
//      return string_hasil;
  }
  function kill_dot(string){
    var string_hasil = "";
    for(i = 0 ; i < string.length ; i++){
      if(string[i] != "."){
        if(string[i] == ",")
          string_hasil = string_hasil + ".";
        else
          string_hasil = string_hasil + string[i];
      }
    }
    return string_hasil;
  }
  function total_unit_belanja(){
    var baru = $('#target_service_belanja').text();
    var belanja = $('#target_belanja').text();
    belanja = kill_dot(belanja) * 1;
    baru = kill_dot(baru) * 1;

    var settings = baru + belanja;
    $('#total_belanja').text(get_dot(settings, false));
    target_perday('total_belanja', 'target_perday_total_belanja');
  } 
 function total_unit_entry_service(){
    var baru = $('#target_service_belanja').text();
    var service = $('#target_service').text();
    service = kill_dot(service) * 1;
    baru = kill_dot(baru) * 1;

    var settings = baru + service;
    $('#total_service').text(get_dot(settings, false));
    target_perday('total_service', 'target_perday_total_service');
  }
 function total_transaksi(){
    var belanja = $('#target_belanja').text();
    belanja = kill_dot(belanja) * 1;
    var service_belanja = $('#target_service_belanja').text();
    var service = $('#target_service').text();
    service = kill_dot(service) * 1;
    service_belanja = kill_dot(service_belanja) * 1;

    var settings = service_belanja + service + belanja;
    $('#total_transaksi').text(get_dot(settings, false));
    target_omset_transaksi();
    target_perday('total_transaksi', 'target_perday_total_transaksi');
  }
  function pendapatan_lain(){
    <?php
    if(is_array($pendapatan_lain)){
      $hasil_pendapatan = "";
      foreach ($pendapatan_lain as $pl) {
        print "
          var pl_{$pl->id_pendapatan_lain} = $('#pendapatan_{$pl->id_pendapatan_lain}').text();
          pl_{$pl->id_pendapatan_lain} = kill_dot(pl_{$pl->id_pendapatan_lain}) * 1;
          ";
        $hasil_pendapatan .= "pl_".$pl->id_pendapatan_lain." + ";
      }
      $hasil_pendapatan .= "0".";";
    }
    ?>
    var hasil_pendapatan = <?=$hasil_pendapatan?>;
    $('#total_pendapatan_lain').text(get_dot(hasil_pendapatan, false));
    target_perday('total_pendapatan_lain', 'target_perday_total_pendapatan');
    target_laba_rugi();
  }
  function pendapatan_lain_perday(i){
    <?php
    if(is_array($pendapatan_lain)){
      $hasil_pendapatan = "";
      foreach ($pendapatan_lain as $pl) {
        print "
          var pl_{$pl->id_pendapatan_lain} = $('#pend_{$pl->id_pendapatan_lain}_' + i).text();
          pl_{$pl->id_pendapatan_lain} = kill_dot(pl_{$pl->id_pendapatan_lain}) * 1;
          if(isNaN(pl_{$pl->id_pendapatan_lain})){
            pl_{$pl->id_pendapatan_lain} = 0;
          }
          ";
        $hasil_pendapatan .= "pl_".$pl->id_pendapatan_lain." + ";
      }
      $hasil_pendapatan .= "0".";";
    }
    ?>
    var hasil_pendapatan = <?=$hasil_pendapatan?>
    $('#total_pend_perday_'+i).text(get_dot(hasil_pendapatan, false));
    realisasi('total_pend_perday', 'realisasi_total_pendapatan');
    laba_rugi(i);
  }
  function opex_lain(){
    <?php
    if(is_array($opex)){
      $hasil_opex = "";
      foreach ($opex as $pl) {
        print "
          var pl_{$pl->id_opex} = $('#opex_{$pl->id_opex}').text();
          pl_{$pl->id_opex} = kill_dot(pl_{$pl->id_opex}) * 1;
          ";
        $hasil_opex .= "pl_".$pl->id_opex." + ";
      }
      $hasil_opex .= "0".";";
    }
    ?>
    var hasil_opex = <?=$hasil_opex?>;
    $('#total_opex_lain').text(get_dot(hasil_opex, false));
    target_margin();
    target_perday('total_opex_lain', 'target_perday_total_opex');
  }
  function opex_perday(i){
    <?php
    if(is_array($opex)){
      $hasil_opex = "";
      foreach ($opex as $pl) {
        print "
          var pl_{$pl->id_opex} = $('#opex_{$pl->id_opex}_' + i).text();
          pl_{$pl->id_opex} = kill_dot(pl_{$pl->id_opex}) * 1;
          if(isNaN(pl_{$pl->id_opex})){
            pl_{$pl->id_opex} = 0;
          }
          ";
        $hasil_opex .= "pl_".$pl->id_opex." + ";
      }
      $hasil_opex .= "0".";";
    }
    ?>
    var hasil_opex = <?=$hasil_opex?>;
    $('#total_opex_perday_'+i).text(get_dot(hasil_opex, false));
    margin(i);
    realisasi('total_opex_perday', 'realisasi_total_opex');
  }
  function service_perday(i){
    var sv_perday = $('#service_'+i).text();
    sv_perday = kill_dot(sv_perday) * 1;
    if(isNaN(sv_perday)){
      sv_perday = 0;
    }
    var sv_b_perday = $('#service_belanja_'+i).text();
    sv_b_perday = kill_dot(sv_b_perday) * 1;
    if(isNaN(sv_b_perday)){
      sv_b_perday = 0;
    }
    var total = sv_perday + sv_b_perday;
    $('#total_service_perday_'+i).text(get_dot(total, false));
    realisasi('total_service_perday', 'realisasi_total_service');
  }
  function belanja_perday(i){
    var bl_perday = $('#belanja_'+i).text();
    bl_perday = kill_dot(bl_perday) * 1;
    if(isNaN(bl_perday)){
      bl_perday = 0;
    }
    var sv_b_perday = $('#service_belanja_'+i).text();
    sv_b_perday = kill_dot(sv_b_perday) * 1;
    if(isNaN(sv_b_perday)){
      sv_b_perday = 0;
    }
    var total = bl_perday + sv_b_perday;
    $('#total_belanja_perday_'+i).text(get_dot(total, false));
    realisasi('total_belanja_perday', 'realisasi_total_belanja');
  }
  function transaksi_perday(i){
    var bl_perday = $('#belanja_'+i).text();
    bl_perday = kill_dot(bl_perday) * 1;
    if(isNaN(bl_perday)){
      bl_perday = 0;
    }
    var sv_b_perday = $('#service_belanja_'+i).text();
    sv_b_perday = kill_dot(sv_b_perday) * 1;
    if(isNaN(sv_b_perday)){
      sv_b_perday = 0;
    }
    var sv_perday = $('#service_'+i).text();
    sv_perday = kill_dot(sv_perday) * 1;
    if(isNaN(sv_perday)){
      sv_perday = 0;
    }
    var total = bl_perday + sv_b_perday + sv_perday;
    $('#total_transaksi_perday_'+i).text(get_dot(total, false));
    realisasi('total_transaksi_perday', 'realisasi_total_transaksi');
  }
  function penerimaan_service_perday(i){
    var sv_perday = $('#p_service_'+i).text();
    sv_perday = kill_dot(sv_perday) * 1;
    if(isNaN(sv_perday)){
      sv_perday = 0;
    }
    var p_sv_perday = $('#p_service_plus_'+i).text();
    p_sv_perday = kill_dot(p_sv_perday) * 1;
    if(isNaN(p_sv_perday)){
      p_sv_perday = 0;
    }
    var bl_perday = $('#p_belanja_plus_'+i).text();
    bl_perday = kill_dot(bl_perday) * 1;
    if(isNaN(bl_perday)){
      bl_perday = 0;
    }
    var p_bl_perday = $('#p_belanja_'+i).text();
    p_bl_perday = kill_dot(p_bl_perday) * 1;
    if(isNaN(p_bl_perday)){
      p_bl_perday = 0;
    }
    var total = sv_perday + p_sv_perday + bl_perday + p_bl_perday;
    $('#total_penerimaan_perday_'+i).text(get_dot(total, false));
    realisasi('total_penerimaan_perday', 'realisasi_total_penerimaan_perday');
    gross_margin(i);
  }
  function omset_perday(i){
    var total_trans = $('#total_transaksi_perday_'+i).text();
    total_trans = kill_dot(total_trans) * 1;
    if(isNaN(total_trans)){
      total_trans = 1;
    }
    else if(total_trans == 0){
      total_trans = 1;
    }
    var total_penerimaan = $('#total_penerimaan_perday_'+i).text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total = total_penerimaan/total_trans;
    $('#total_omset_perday_'+i).text(get_dot(total, true));
//    realisasi('total_omset_perday', 'realisasi_total_omset_perday');
  }
  function omset_global(total_transaksi_param, total_penerimaan_param, target){
    var total_trans = $('#'+total_transaksi_param).text();
    total_trans = kill_dot(total_trans) * 1;
    if(isNaN(total_trans)){
      total_trans = 1;
    }
    else if(total_trans == 0){
      total_trans = 1;
    }
    var total_penerimaan = $('#'+total_penerimaan_param).text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total = total_penerimaan/total_trans;
    $('#'+target).text(get_dot(total, true));
//    realisasi('total_omset_perday', 'realisasi_total_omset_perday');
  }
  function target_penerimaan_service(){
    var target_service = $('#target_rata_service').text();
    target_service = kill_dot(target_service) * 1;
    if(isNaN(target_service)){
      target_service = 0;
    }
    var target_t_service = $('#target_service').text();
    target_t_service = kill_dot(target_t_service) * 1;
    if(isNaN(target_t_service)){
      target_t_service = 0;
    }
    var total = target_service * target_t_service;
    $('#target_penerimaan_service').text(get_dot(total, false));
    target_perday('target_penerimaan_service', 'target_perday_p_service');
  }
  function target_penerimaan_service_plus(){
    var target_service = $('#target_rata_service').text();
    target_service = kill_dot(target_service) * 1;
    if(isNaN(target_service)){
      target_service = 0;
    }
    var target_t_service_belanja = $('#target_service_belanja').text();
    target_t_service_belanja = kill_dot(target_t_service_belanja) * 1;
    if(isNaN(target_t_service_belanja)){
      target_t_service_belanja = 0;
    }
    var total = target_service * target_t_service_belanja;
    $('#target_penerimaan_service_plus').text(get_dot(total, false));
    target_perday('target_penerimaan_service_plus', 'target_perday_p_service_plus');
  }
  function target_penerimaan_belanja_plus(){
    var target_service = $('#target_rata_belanja').text();
    target_service = kill_dot(target_service) * 1;
    if(isNaN(target_service)){
      target_service = 0;
    }
    var target_t_service_belanja = $('#target_service_belanja').text();
    target_t_service_belanja = kill_dot(target_t_service_belanja) * 1;
    if(isNaN(target_t_service_belanja)){
      target_t_service_belanja = 0;
    }
    var total = target_service * target_t_service_belanja;
    $('#target_penerimaan_belanja_plus').text(get_dot(total, false));
    target_total_hpp();
    target_perday('target_penerimaan_belanja_plus', 'target_perday_p_belanja_plus');
  }
  function target_penerimaan_belanja(){
    var target_service = $('#target_rata_belanja').text();
    target_service = kill_dot(target_service) * 1;
    if(isNaN(target_service)){
      target_service = 0;
    }
    var target_t_service_belanja = $('#target_belanja').text();
    target_t_service_belanja = kill_dot(target_t_service_belanja) * 1;
    if(isNaN(target_t_service_belanja)){
      target_t_service_belanja = 0;
    }
    var total = target_service * target_t_service_belanja;
    $('#target_penerimaan_belanja').text(get_dot(total, false));
    target_total_hpp();
    target_perday('target_penerimaan_belanja', 'target_perday_p_belanja');
  }
  function target_total_penerimaan(){
    var target_service = $('#target_penerimaan_service').text();
    target_service = kill_dot(target_service) * 1;
    if(isNaN(target_service)){
      target_service = 0;
    }
    
    var target_service_plus = $('#target_penerimaan_service_plus').text();
    target_service_plus = kill_dot(target_service_plus) * 1;
    if(isNaN(target_service_plus)){
      target_service_plus = 0;
    }
    
    var target_belanja_plus = $('#target_penerimaan_belanja_plus').text();
    target_belanja_plus = kill_dot(target_belanja_plus) * 1;
    if(isNaN(target_belanja_plus)){
      target_belanja_plus = 0;
    }
    
    var target_belanja = $('#target_penerimaan_belanja').text();
    target_belanja = kill_dot(target_belanja) * 1;
    if(isNaN(target_belanja)){
      target_belanja = 0;
    }
    
    var total = target_service + target_service_plus + target_belanja_plus + target_belanja;
    $('#target_total_penerimaan').text(get_dot(total, false));
    target_omset_transaksi();
    target_gross_margin();
    target_perday('target_total_penerimaan', 'target_perday_total_penerimaan');
  }
  function target_omset_transaksi(){
    var target_penerimaan = $('#target_total_penerimaan').text();
    target_penerimaan = kill_dot(target_penerimaan) * 1;
    if(isNaN(target_penerimaan)){
      target_penerimaan = 0;
    }
    var target_transaksi = $('#total_transaksi').text();
    target_transaksi = kill_dot(target_transaksi) * 1;
    if(isNaN(target_transaksi)){
      target_transaksi = 1;
    }
    else if(target_transaksi == 0)
      target_transaksi = 1;
      
    var total = target_penerimaan / target_transaksi;
    $('#target_omset_transaksi').text(get_dot(total, false));
//    target_perday('target_omset_transaksi', 'target_perday_total_omset');
    target_perday('target_gross_margin', 'target_perday_gross_margin');
  }
  function target_total_hpp(){
    var belanja_plus = $('#target_penerimaan_belanja_plus').text();
    belanja_plus = kill_dot(belanja_plus) * 1;
    if(isNaN(belanja_plus)){
      belanja_plus = 0;
    }
    var belanja = $('#target_penerimaan_belanja').text();
    belanja = kill_dot(belanja) * 1;
    if(isNaN(belanja)){
      belanja = 0;
    }
    var hpp = $('#target_hpp').text();
    hpp = kill_dot(hpp) * 1;
    if(isNaN(hpp)){
      hpp = 0;
    }
      
    var total = (belanja_plus + belanja) * (hpp / 100);
    $('#target_total_hpp').text(get_dot(total, false));
    target_gross_margin();
  }
  function target_gross_margin(){
    var total_penerimaan = $('#target_total_penerimaan').text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total_hpp = $('#target_total_hpp').text();
    total_hpp = kill_dot(total_hpp) * 1;
    if(isNaN(total_hpp)){
      total_hpp = 0;
    }
      
    var total = total_penerimaan - total_hpp;
    $('#target_gross_margin').text(get_dot(total, false));
    target_margin();
  }
  function gross_margin(i){
    var total_penerimaan = $('#total_penerimaan_perday_'+i).text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total_hpp = $('#total_hpp_'+i).text();
    total_hpp = kill_dot(total_hpp) * 1;
    if(isNaN(total_hpp)){
      total_hpp = 0;
    }
      
    var total = total_penerimaan - total_hpp;
    $('#gross_margin_'+i).text(get_dot(total, false));
    margin(i);
    realisasi('gross_margin', 'realisasi_gross_margin');
    realisasi('margin', 'realisasi_margin');
  }
  function margin(i){
    
    var total_penerimaan = $('#gross_margin_'+i).text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total_hpp = $('#total_opex_perday_'+i).text();
    total_hpp = kill_dot(total_hpp) * 1;
    if(isNaN(total_hpp)){
      total_hpp = 0;
    }
    
    var total = total_penerimaan - total_hpp;
    $('#margin_'+i).text(get_dot(total, false));
    laba_rugi(i);
    realisasi('laba_rugi', 'realisasi_laba_rugi');
    realisasi('margin', 'realisasi_margin');
  }
  function target_margin(){
    var total_penerimaan = $('#target_gross_margin').text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total_beban= $('#total_opex_lain').text();
    total_beban = kill_dot(total_beban) * 1;
    if(isNaN(total_beban)){
      total_beban = 0;
    }
      
    var total = total_penerimaan - total_beban;
    $('#target_margin').text(get_dot(total, false));
    target_laba_rugi();
    target_perday('target_margin', 'target_perday_margin');
    target_perday('target_laba_rugi', 'target_perday_laba_rugi');
  }
  function target_laba_rugi(){
    var total_penerimaan = $('#target_margin').text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total_pendapatan_lain = $('#total_pendapatan_lain').text();
    total_pendapatan_lain = kill_dot(total_pendapatan_lain) * 1;
    if(isNaN(total_pendapatan_lain)){
      total_pendapatan_lain = 0;
    }
      
    var total = total_penerimaan + total_pendapatan_lain;
    $('#target_laba_rugi').text(get_dot(total, false));
  }
  function realisasi_service(){
    var total = 0;
    <?php
    $tambah = "";
    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
    ?>
      var total_penerimaan_<?=$i?> = $('#service_<?=$i?>').text();
      total_penerimaan_<?=$i?> = kill_dot(total_penerimaan_<?=$i?>) * 1;
      if(isNaN(total_penerimaan_<?=$i?>)){
        total_penerimaan_<?=$i?> = 0;
      }
    <?php
      $tambah .= "total_penerimaan_{$i} + ";
    }
    $tambah .= 0;
    ?>
    total = <?=$tambah?>;
    $('#realisasi_service').text(get_dot(total, false));
    rata_rupiah('realisasi_p_service', "realisasi_p_service_plus", 'realisasi_service', 'realisasi_service_belanja', 'realisasi_rata_service');
  }
  function realisasi(param, target){
    var total = 0;
    <?php
    $tambah = "";
    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
    ?>
      var total_penerimaan_<?=$i?> = $('#'+param+'_<?=$i?>').text();
      total_penerimaan_<?=$i?> = kill_dot(total_penerimaan_<?=$i?>) * 1;
      if(isNaN(total_penerimaan_<?=$i?>)){
        total_penerimaan_<?=$i?> = 0;
      }
    <?php
      $tambah .= "total_penerimaan_{$i} + ";
    }
    $tambah .= 0;
    ?>
    total = <?=$tambah?>;
    $('#'+target).text(get_dot(total, false));
    achievement('realisasi_service', 'target_perday_service', 'achievement_service');
    achievement('realisasi_service_belanja', 'target_perday_service_belanja', 'achievement_service_belanja');
    achievement('realisasi_belanja', 'target_perday_belanja', 'achievement_belanja');
    achievement('realisasi_total_service', 'target_perday_total_service', 'achievement_total_service');
    achievement('realisasi_total_belanja', 'target_perday_total_belanja', 'achievement_total_belanja');
    achievement('realisasi_total_transaksi', 'target_perday_total_transaksi', 'achievement_total_transaksi');
    
    achievement('realisasi_p_service', 'target_perday_p_service', 'achievement_p_service');
    achievement('realisasi_p_service_plus', 'target_perday_p_service_plus', 'achievement_p_service_plus');
    achievement('realisasi_p_belanja_plus', 'target_perday_p_belanja_plus', 'achievement_p_belanja_plus');
    achievement('realisasi_p_belanja', 'target_perday_p_belanja', 'achievement_p_belanja');
    achievement('realisasi_total_penerimaan_perday', 'target_perday_total_penerimaan', 'achievement_total_penerimaan');
    achievement('realisasi_total_omset_perday', 'target_perday_total_omset', 'achievement_total_omset');
    
    achievement('realisasi_rata_service', 'target_perday_rata_service', 'achievement_rata_service');
    achievement('realisasi_rata_belanja', 'target_perday_rata_belanja', 'achievement_rata_belanja');
    
    achievement('realisasi_total_opex', 'target_perday_total_opex', 'achievement_total_opex');
    achievement('realisasi_total_pendapatan', 'target_perday_total_pendapatan', 'achievement_total_pendapatan');
    
    achievement('realisasi_margin', 'target_perday_margin', 'achievement_margin');
    achievement('realisasi_laba_rugi', 'target_perday_laba_rugi', 'achievement_laba_rugi');
    
    achievement('realisasi_hpp', 'target_perday_hpp', 'achievement_hpp');
    achievement('realisasi_total_hpp', 'target_perday_total_hpp', 'achievement_total_hpp');
    
    achievement('realisasi_gross_margin', 'target_perday_gross_margin', 'achievement_gross_margin');
    
    rata_rupiah('realisasi_p_service', "realisasi_p_service_plus", 'realisasi_service', 'realisasi_service_belanja', 'realisasi_rata_service');
    rata_rupiah('realisasi_p_belanja', "realisasi_p_belanja_plus", 'realisasi_belanja', 'realisasi_service_belanja', 'realisasi_rata_belanja');
    
    omset_global('realisasi_total_transaksi', 'realisasi_total_penerimaan_perday', 'realisasi_total_omset_perday');
    
    omset_global('target_perday_total_transaksi', 'target_perday_total_penerimaan', 'target_perday_total_omset');
    
    <?php
    if(is_array($opex)){
      $hasil_opex = "";
      foreach ($opex as $pl) {
        print "
          achievement('realisasi_opex_{$pl->id_opex}', 'target_perday_opex_{$pl->id_opex}', 'achievement_opex_{$pl->id_opex}');
          ";
      }
    }
    if(is_array($pendapatan_lain)){
      foreach ($pendapatan_lain as $pl) {
        print "
          achievement('realisasi_pendapatan_{$pl->id_pendapatan_lain}', 'target_perday_pendapatan_{$pl->id_pendapatan_lain}', 'achievement_pendapatan_{$pl->id_pendapatan_lain}');
          ";
      }
    }
    ?>
  }
  function target_perday(param, target){
    var total = 0;
    var total_penerimaan = $('#'+param).text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var inputdata = $('#inputdata').text() * 1;
    total = (inputdata / <?=$detail[0]->day_in_month?> * total_penerimaan);
    $('#'+target).text(get_dot(total, true));
    achievement('realisasi_service', 'target_perday_service', 'achievement_service');
    achievement('realisasi_service_belanja', 'target_perday_service_belanja', 'achievement_service_belanja');
    achievement('realisasi_belanja', 'target_perday_belanja', 'achievement_belanja');
    achievement('realisasi_total_service', 'target_perday_total_service', 'achievement_total_service');
    achievement('realisasi_total_belanja', 'target_perday_total_belanja', 'achievement_total_belanja');
    achievement('realisasi_total_transaksi', 'target_perday_total_transaksi', 'achievement_total_transaksi');
    
    achievement('realisasi_p_service', 'target_perday_p_service', 'achievement_p_service');
    achievement('realisasi_p_service_plus', 'target_perday_p_service_plus', 'achievement_p_service_plus');
    achievement('realisasi_p_belanja_plus', 'target_perday_p_belanja_plus', 'achievement_p_belanja_plus');
    achievement('realisasi_p_belanja', 'target_perday_p_belanja', 'achievement_p_belanja');
    achievement('realisasi_total_penerimaan_perday', 'target_perday_total_penerimaan', 'achievement_total_penerimaan');
    achievement('realisasi_total_omset_perday', 'target_perday_total_omset', 'achievement_total_omset');
    
    achievement('realisasi_rata_service', 'target_perday_rata_service', 'achievement_rata_service');
    achievement('realisasi_rata_belanja', 'target_perday_rata_belanja', 'achievement_rata_belanja');
    
    achievement('realisasi_total_opex', 'target_perday_total_opex', 'achievement_total_opex');
    achievement('realisasi_total_pendapatan', 'target_perday_total_pendapatan', 'achievement_total_pendapatan');
    
    achievement('realisasi_margin', 'target_perday_margin', 'achievement_margin');
    achievement('realisasi_laba_rugi', 'target_perday_laba_rugi', 'achievement_laba_rugi');
    
    achievement('realisasi_hpp', 'target_perday_hpp', 'achievement_hpp');
    achievement('realisasi_total_hpp', 'target_perday_total_hpp', 'achievement_total_hpp');
    
    <?php
    if(is_array($opex)){
      $hasil_opex = "";
      foreach ($opex as $pl) {
        print "
          achievement('realisasi_opex_{$pl->id_opex}', 'target_perday_opex_{$pl->id_opex}', 'achievement_opex_{$pl->id_opex}');
          ";
      }
    }
    if(is_array($pendapatan_lain)){
      foreach ($pendapatan_lain as $pl) {
        print "
          achievement('realisasi_pendapatan_{$pl->id_pendapatan_lain}', 'target_perday_pendapatan_{$pl->id_pendapatan_lain}', 'achievement_pendapatan_{$pl->id_pendapatan_lain}');
          ";
      }
    }
    ?>
  }
  function achievement(param, param2, target){
    var total = 0;
    var total_penerimaan = $('#'+param).text();
    total_penerimaan = kill_dot(total_penerimaan) * 1;
    if(isNaN(total_penerimaan)){
      total_penerimaan = 0;
    }
    var total_penerimaan2 = $('#'+param2).text();
    total_penerimaan2 = kill_dot(total_penerimaan2) * 1;
    if(isNaN(total_penerimaan2)){
      total_penerimaan2 = 1;
    }
    else if(total_penerimaan2 == 0)
      total_penerimaan2 = 1;
    total = total_penerimaan / total_penerimaan2 * 100;
    $('#'+target).text(get_dot(total, true));
  }
  function rata_rupiah(rupiah1, rupiah2, param1, param2, target){
    var trupiah1 = $('#'+rupiah1).text();
    trupiah1 = kill_dot(trupiah1) * 1;
    if(isNaN(trupiah1)){
      trupiah1 = 0;
    }
    var trupiah2 = $('#'+rupiah2).text();
    trupiah2 = kill_dot(trupiah2) * 1;
    if(isNaN(trupiah2)){
      trupiah2 = 0;
    }
    var tparam1 = $('#'+param1).text();
    tparam1 = kill_dot(tparam1) * 1;
    if(isNaN(tparam1)){
      tparam1 = 0;
    }
    var tparam2 = $('#'+param2).text();
    tparam2 = kill_dot(tparam2) * 1;
    if(isNaN(tparam2)){
      tparam2 = 0;
    }
    
    var gtparam = tparam1 + tparam2;
    if(gtparam <= 0)
      gtparam = 1;
    
    total = (trupiah1 + trupiah2) / gtparam;
    $('#'+target).text(get_dot(total, true));
//    realisasi('rata_service', 'realisasi_rata_service');
//    realisasi('rata_belanja', 'realisasi_rata_belanja');
  }
  function persentase_hpp(param1, param2, rupiah, targeti){
    var barang1 = $('#'+param1).text();
    barang1 = kill_dot(barang1) * 1;
    if(isNaN(barang1)){
      barang1 = 0;
    }
    var barang2 = $('#'+param2).text();
    barang2 = kill_dot(barang2) * 1;
    if(isNaN(barang2)){
      barang2 = 0;
    }
    var gbarang = barang1 + barang2;
    if(gbarang == 0)
      gbarang = 1;
    
    var harga = $('#'+rupiah).text();
    harga = kill_dot(harga) * 1;
    if(isNaN(harga)){
      harga = 0;
    }
    total = harga / gbarang * 100;
    $('#'+targeti).text(get_dot(total, true));
  }
  function laba_rugi(i){
    var margin = $('#margin_'+i).text();
    margin = kill_dot(margin) * 1;
    if(isNaN(margin)){
      margin = 0;
    }
    
    var pendapatan = $('#total_pend_perday_'+i).text();
    pendapatan = kill_dot(pendapatan) * 1;
    if(isNaN(pendapatan)){
      pendapatan = 0;
    }
    total = margin + pendapatan;
    $('#laba_rugi_'+i).text(get_dot(total, false));
  }
  function plus_day(i){
    var inputdata = $('#inputdata').text() * 1;
    if(i >= inputdata)
      var hasil = i;
    else
      var hasil = inputdata;
    
    $('#inputdata').text(hasil);
    target_perday('target_service', 'target_perday_service');
    target_perday('target_service_belanja', 'target_perday_service_belanja');
    target_perday('target_belanja', 'target_perday_belanja');
    target_perday('total_service', 'target_perday_total_service');
    target_perday('total_belanja', 'target_perday_total_belanja');
    target_perday('total_transaksi', 'target_perday_total_transaksi');
    target_perday('target_penerimaan_service', 'target_perday_p_service');
    
    target_perday('target_penerimaan_service_plus', 'target_perday_p_service_plus');
    target_perday('target_penerimaan_belanja_plus', 'target_perday_p_belanja_plus');
    target_perday('target_penerimaan_belanja', 'target_perday_p_belanja');
    target_perday('target_total_penerimaan', 'target_perday_total_penerimaan');
//    target_perday('target_omset_transaksi', 'target_perday_total_omset');
  
//    target_perday('target_rata_service', 'target_perday_rata_service');
//    target_perday('target_rata_belanja', 'target_perday_rata_belanja');
  
    target_perday('total_opex_lain', 'target_perday_total_opex');
  
    target_perday('total_pendapatan_lain', 'target_perday_total_pendapatan');
  
    target_perday('target_margin', 'target_perday_margin');
  
    target_perday('target_laba_rugi', 'target_perday_laba_rugi');
  
  
    target_perday('target_total_hpp', 'target_perday_total_hpp');
  
    target_perday('target_gross_margin', 'target_perday_gross_margin');
  
    <?php
    if(is_array($opex)){
      $hasil_opex = "";
      foreach ($opex as $pl) {
        print "
          target_perday('opex_{$pl->id_opex}', 'target_perday_opex_{$pl->id_opex}');
          ";
      }
    }
    if(is_array($pendapatan_lain)){
      foreach ($pendapatan_lain as $pl) {
        print "
          target_perday('pendapatan_{$pl->id_pendapatan_lain}', 'target_perday_pendapatan_{$pl->id_pendapatan_lain}');
          ";
      }
    }
    ?>
  }
</script>
<div id="main-content">
  <div class="container-fluid">
    <div class="row-fluid">
      <div class="span12">
        <div class="widget-block">
          <div style="display: none" id="inputdata"><?=$hari_ke?></div>
          <?php
          if($message == 'filed'){
          ?>
          <div class="alert alert-error fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <strong>Filed!</strong> Fail to save data.
          </div>
          <?php
          }
          if($message == 'sukses'){
          ?>
          <div class="alert alert-success fade in">
            <button data-dismiss="alert" class="close" type="button">×</button>
            <strong>Success!</strong> Now you have new user.
          </div>
          <?php
          }
          ?>
          <div class="widget-head">
            <h5><?=$title_table?></h5>
            <div class="widget-control pull-right">
              <a href="#" data-toggle="dropdown" class="btn dropdown-toggle"><i class="icon-cog"></i><b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="<?=  site_url("outlet/aktifitas/pica/".$detail[0]->id_actifity_report) ?>"><i class="icon-plus"></i> History</a></li>
                <li><a href="<?=  site_url("outlet/aktifitas/history/".$detail[0]->id_actifity_report) ?>"><i class="icon-plus"></i> PICA</a></li>
                <li><a href="<?=  site_url("outlet/aktifitas/unit-entry-chart/".$detail[0]->id_actifity_report) ?>"><i class="icon-plus"></i> Chart Unit Entry</a></li>
<!--                <li><a href="#"><i class="icon-ok"></i> Active</a></li>
                <li><a href="#"><i class="icon-minus-sign"></i> No-Active</a></li>
                <li><a href="#"><i class="black-icons pdf_document"></i> Export to PDF</a></li>-->
                <li><a href="<?=  site_url("outlet/aktifitas/half-export-xls/".$detail[0]->id_actifity_report) ?>"><i class="black-icons excel_document"></i>XLS (1-15)</a></li>
                <li><a href="<?=  site_url("outlet/aktifitas/fs-export-xls/".$detail[0]->id_actifity_report) ?>"><i class="black-icons excel_document"></i> Export to XLS</a></li>
              </ul>
            </div>
          </div>
          <div class="widget-content">
            <div class="widget-box">
              <table class="table" border="1">
                <thead>
                  <tr style="background-color: #8cafed">
                    <th colspan="2">Keterangan </th>
                    <th colspan="2">Target</th>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <th>{$i}</th>
EOD;
                    }
                    ?>
                    <th>Realisasi</th>
                    <th>Target Hingga <br />Hari ini</th>
                    <th colspan="2">Achievement</th>
                  </tr>
                </thead>
                <tbody>
                  <tr style="background-color: #0F7">
                    <th colspan="<?=$detail[0]->day_in_month + 8?>">UNIT ENTRY</th>
                  </tr>
                  <tr>
                    <td colspan="2">Servis Saja</td>
                    <td colspan="2" style="text-align: right" class="warna_target">
                      <?=$this->form_eksternal->form_text_editable("target_service", site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report), number_format($data_target[0]->service, 0, ",", "."), "callback : function(value, settings) {
              total_unit_entry_service();
              total_transaksi();
              target_penerimaan_service();
              target_total_penerimaan();
              realisasi_service();
              target_perday('target_service', 'target_perday_service');
            }", "", $privilege, $data_target[0]->service)?>
                    </td>
                       <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                    
                    /*  $go_service_perhari = $this->form_eksternal->form_text_editable("service_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->service, 0, ",", "."), "callback : function(value, settings) {
              service_perday({$i});
              transaksi_perday({$i});
              omset_perday({$i});
              realisasi('service', 'realisasi_service');
              rata_rupiah('p_service_{$i}', 'p_service_plus_{$i}','service_{$i}', 'service_belanja_{$i}', 'rata_service_{$i}');
              plus_day({$i});
            }", "", $privilege, $data_harian[$i]->service); */
                      print <<<EOD
                     <td style="text-align: right" class="warna_harian"><span id="service_{$i}">{$data_harian[$i]->service}</span></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_service"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_service"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_service"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <td colspan="2">Servis + Belanja</td>
                    <td colspan="2" style="text-align: right" class="warna_target">
                      <?=$this->form_eksternal->form_text_editable("target_service_belanja", site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report), number_format($data_target[0]->service_belanja, 0, ",", "."), "callback : function(value, settings) {
              total_unit_entry_service();
              total_unit_belanja();
              total_transaksi();
              target_penerimaan_service_plus();
              target_penerimaan_belanja_plus();
              target_total_penerimaan();
              target_perday('target_service_belanja', 'target_perday_service_belanja');
            }", "", $privilege, $data_target[0]->service_belanja)?>
                    </td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                   /*   $go_service_belanja_perhari = $this->form_eksternal->form_text_editable("service_belanja_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->service_belanja, 0, ",", "."), "callback : function(value, settings) {
              service_perday({$i});
              belanja_perday({$i});
              transaksi_perday({$i});
              omset_perday({$i});
              realisasi('service_belanja', 'realisasi_service_belanja');
              rata_rupiah('p_service_{$i}', 'p_service_plus_{$i}','service_{$i}', 'service_belanja_{$i}', 'rata_service_{$i}');
              rata_rupiah('p_belanja_{$i}', 'p_belanja_plus_{$i}','belanja_{$i}', 'service_belanja_{$i}', 'rata_belanja_{$i}');
              plus_day({$i});
            }", "", $privilege, $data_harian[$i]->service_belanja); */
                      print <<<EOD
                     <td style="text-align: right" class="warna_harian"><span id="service_belanja_{$i}">{$data_harian[$i]->service_belanja}</span></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_service_belanja"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_service_belanja"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_service_belanja"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <td colspan="2">Belanja Saja</td>
                    <td colspan="2" style="text-align: right" class="warna_target">
                      <?=$this->form_eksternal->form_text_editable("target_belanja", site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report), number_format($data_target[0]->belanja, 0, ",", "."), "callback : function(value, settings) {
              total_unit_belanja();
              total_transaksi();
              target_penerimaan_belanja();
              target_total_penerimaan();
              target_perday('target_belanja', 'target_perday_belanja');
            }", "", $privilege, $data_target[0]->belanja)?>
                    </td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                    /*  $go_belanja_perhari = $this->form_eksternal->form_text_editable("belanja_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->belanja, 0, ",", "."), "callback : function(value, settings) {
              belanja_perday({$i});
              transaksi_perday({$i});
              omset_perday({$i});
              realisasi('belanja', 'realisasi_belanja');
              rata_rupiah('p_belanja_{$i}', 'p_belanja_plus_{$i}','belanja_{$i}', 'service_belanja_{$i}', 'rata_belanja_{$i}');
              plus_day({$i});
            }", "", $privilege, $data_harian[$i]->belanja); */
                      print <<<EOD
                     <td style="text-align: right" class="warna_harian"><span id="belanja_{$i}">{$data_harian[$i]->belanja}</span></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_belanja"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_belanja"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_belanja"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <th colspan="2">Total Unit Entry Service</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="total_service"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right; font-weight: bold"><div id="total_service_perday_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_service"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_service"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_service"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <th colspan="2">Total Unit Belanja</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="total_belanja"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right; font-weight: bold"><div id="total_belanja_perday_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_belanja"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_belanja"></div></td>
                   <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_belanja"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #AAA">
                    <th colspan="2">Total Transaksi</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="total_transaksi"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right; font-weight: bold"><div id="total_transaksi_perday_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_transaksi"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_transaksi"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_transaksi"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #0F7">
                    <th colspan="<?=$detail[0]->day_in_month + 8?>">PENERIMAAN</th>
                  </tr>
                  <tr>
                    <th colspan="2">Rata-Rata Rupiah Service</th>
                    <td colspan="2" style="text-align: right; font-weight: bold" class="warna_target">
                      <?=$this->form_eksternal->form_text_editable("target_rata_service", site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report), number_format($data_target[0]->rata_service, 0, ",", "."), "callback : function(value, settings) {
              target_penerimaan_service();
              target_penerimaan_service_plus();
              target_total_penerimaan();
            }", "", $privilege, $data_target[0]->rata_service)?>
                    </td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right; font-weight: bold"><div id="rata_service_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_rata_service"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_rata_service"><?=number_format($data_target[0]->rata_service, 0, ",", ".")?></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_rata_service"></div></td>
                    <td style="border: 0; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <th colspan="2">Rata-Rata Rupiah Belanja</th>
                    <td colspan="2" style="text-align: right; font-weight: bold" class="warna_target">
                      <?=$this->form_eksternal->form_text_editable("target_rata_belanja", site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report), number_format($data_target[0]->rata_belanja, 0, ",", "."), "callback : function(value, settings) {
             target_penerimaan_belanja_plus();
             target_penerimaan_belanja();
             target_total_penerimaan();
            }", "", $privilege, $data_target[0]->rata_belanja)?>
                    </td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right; font-weight: bold"><div id="rata_belanja_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_rata_belanja"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_rata_belanja"><?=number_format($data_target[0]->rata_belanja, 0, ",", ".")?></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_rata_belanja"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <td colspan="2">Servis Saja</td>
                    <td colspan="2" style="text-align: right;"><div id="target_penerimaan_service"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                    /*  $go_p_service_perhari = $this->form_eksternal->form_text_editable("p_service_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->p_service, 0, ",", "."), "callback : function(value, settings) {
              penerimaan_service_perday({$i});
              omset_perday({$i});
              realisasi('p_service', 'realisasi_p_service');
              rata_rupiah('p_service_{$i}', 'p_service_plus_{$i}','service_{$i}', 'service_belanja_{$i}', 'rata_service_{$i}');
              plus_day({$i});
            }", "", $privilege, $data_harian[$i]->p_service); */
                      print <<<EOD
                     <td style="text-align: right" class="warna_harian"><span id"p_service_{$i}">{$data_harian[$i]->p_service}</span></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_p_service"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_p_service"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_p_service"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <td rowspan="2">Servis&nbsp;&nbsp;+&nbsp;&nbsp;Belanja</td>
                    <td>Servis</td>
                    <td colspan="2" style="text-align: right;"><div id="target_penerimaan_service_plus"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                    /*  $go_p_service_plus_perhari = $this->form_eksternal->form_text_editable("p_service_plus_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->p_service_plus, 0, ",", "."), "callback : function(value, settings) {
              penerimaan_service_perday({$i});
              omset_perday({$i});
              realisasi('p_service_plus', 'realisasi_p_service_plus');
              rata_rupiah('p_service_{$i}', 'p_service_plus_{$i}','service_{$i}', 'service_belanja_{$i}', 'rata_service_{$i}');
              plus_day({$i});
            }", "", $privilege, $data_harian[$i]->p_service_plus); */
                      print <<<EOD
                     <td style="text-align: right" class="warna_harian"><span id="p_service_plus_{$i}">{$data_harian[$i]->p_service_plus}</span></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_p_service_plus"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_p_service_plus"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_p_service_plus"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <td>Belanja</td>
                    <td colspan="2" style="text-align: right;"><div id="target_penerimaan_belanja_plus"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                    /*  $go_p_belanja_plus_perhari = $this->form_eksternal->form_text_editable("p_belanja_plus_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->p_belanja_plus, 0, ",", "."), "callback : function(value, settings) {
              penerimaan_service_perday({$i});
              omset_perday({$i});
              realisasi('p_belanja_plus', 'realisasi_p_belanja_plus');
              rata_rupiah('p_belanja_{$i}', 'p_belanja_plus_{$i}','belanja_{$i}', 'service_belanja_{$i}', 'rata_belanja_{$i}');
              persentase_hpp('realisasi_p_belanja_plus', 'realisasi_p_belanja', 'realisasi_total_hpp', 'realisasi_hpp');
              persentase_hpp('p_belanja_plus_{$i}', 'p_belanja_{$i}', 'total_hpp_{$i}', 'hpp_{$i}');
              plus_day({$i});
            }", "", $privilege, $data_harian[$i]->p_belanja_plus); */
                      print <<<EOD
                     <td style="text-align: right" class="warna_harian"><span id="p_belanja_plus_{$i}">{$data_harian[$i]->p_belanja_plus}</span></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_p_belanja_plus"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_p_belanja_plus"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_p_belanja_plus"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <td colspan="2">Belanja</td>
                    <td colspan="2" style="text-align: right;"><div id="target_penerimaan_belanja"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                     /* $go_p_belanja_perhari = $this->form_eksternal->form_text_editable("p_belanja_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->p_belanja, 0, ",", "."), "callback : function(value, settings) {
              penerimaan_service_perday({$i});
              omset_perday({$i});
              realisasi('p_belanja', 'realisasi_p_belanja');
              rata_rupiah('p_belanja_{$i}', 'p_belanja_plus_{$i}','belanja_{$i}', 'service_belanja_{$i}', 'rata_belanja_{$i}');
              persentase_hpp('realisasi_p_belanja_plus', 'realisasi_p_belanja', 'realisasi_total_hpp', 'realisasi_hpp');
              persentase_hpp('p_belanja_plus_{$i}', 'p_belanja_{$i}', 'total_hpp_{$i}', 'hpp_{$i}');
              plus_day({$i});
            }", "", $privilege, $data_harian[$i]->p_belanja); */
                      print <<<EOD
                     <td style="text-align: right" class="warna_harian"><span id="p_belanja_{$i}">{$data_harian[$i]->p_belanja}</span></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_p_belanja"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_p_belanja"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_p_belanja"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <th colspan="2">Total PENERIMAAN</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="target_total_penerimaan"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right; font-weight: bold"><div id="total_penerimaan_perday_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_penerimaan_perday"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_penerimaan"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_penerimaan"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #AAA">
                    <th colspan="2">Omset Per Transaksi</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="target_omset_transaksi"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right; font-weight: bold"><div id="total_omset_perday_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_omset_perday"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_omset"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_omset"></div></td>
                    <td style="border: 0;text-align: left; font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #0F7">
                    <th colspan="<?=$detail[0]->day_in_month + 8?>">HARGA POKOK PENJUALAN</th>
                  </tr>
                  <tr>
                    <td colspan="2">% HPP</td>
                    <td style="text-align: right; border: 0" class="warna_target">
                      <?=$this->form_eksternal->form_text_editable("target_hpp", site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report), number_format($data_target[0]->hpp, 0, ",", "."), "callback : function(value, settings) {
              target_total_hpp();
              target_perday('target_total_hpp', 'target_perday_total_hpp');
              target_perday('target_gross_margin', 'target_perday_gross_margin');
            }", "", $privilege, $data_target[0]->hpp)?>
                    </td>
                    <td style="border: 0"> %</td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <td style="text-align: right;"><div id="hpp_{$i}"></div></td>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_hpp"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_hpp"><?=number_format($data_target[0]->hpp, 0, ",", ".")?></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_hpp"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                  <tr>
                    <th colspan="2">Total HPP</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="target_total_hpp"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                     /* $go_total_hpp_perhari = $this->form_eksternal->form_text_editable("total_hpp_".$i, site_url("outlet/aktifitas/olah-editable/".$detail[0]->id_actifity_report."/".$i), number_format($data_harian[$i]->total_hpp, 0, ",", "."), "callback : function(value, settings) {
                        gross_margin({$i});
                        persentase_hpp('p_belanja_plus_{$i}', 'p_belanja_{$i}', 'total_hpp_{$i}', 'hpp_{$i}');
                        persentase_hpp('realisasi_p_belanja_plus', 'realisasi_p_belanja', 'realisasi_total_hpp', 'realisasi_hpp');
                        realisasi('total_hpp', 'realisasi_total_hpp');
                        target_perday('target_total_hpp', 'target_perday_total_hpp');
                        realisasi('gross_margin', 'realisasi_gross_margin');
                        target_perday('target_gross_margin', 'target_perday_gross_margin');
                        plus_day({$i});
            }", "", $privilege, $data_harian[$i]->total_hpp); */
                      print <<<EOD
                    <th style="text-align: right;" class="warna_harian"><span id="total_hpp_{$i}">{$data_harian[$i]->total_hpp}</span></th>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_hpp"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_hpp"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_hpp"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #AAA">
                    <th colspan="2">GROSS MARGIN</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="target_gross_margin"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <th style="text-align: right;"><div id="gross_margin_{$i}"></div></th>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_gross_margin"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_gross_margin"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_gross_margin"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #0F7">
                    <th colspan="<?=$detail[0]->day_in_month + 8?>">OPERATIONAL EXPENSE (OPEX)</th>
                  </tr>
                  <?php
                  if(is_array($opex)){
                    foreach ($opex as $pl) {
                      $tengah = "";
                      for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                        $go_opex_perhari = $this->form_eksternal->form_text_editable("opex_".$pl->id_opex."_".$i, site_url("outlet/aktifitas/olah-editable-dinamis/opex/".$detail[0]->id_actifity_report."/{$pl->id_opex}/{$i}"), number_format($data_opex_perday[$pl->id_opex][$i], 0, ",", "."), "callback : function(value, settings) {
              opex_perday({$i});
              realisasi('opex_{$pl->id_opex}', 'realisasi_opex_{$pl->id_opex}');
              target_perday('opex_{$pl->id_opex}', 'target_perday_opex_{$pl->id_opex}');
              plus_day({$i});
            }", "", $privilege, $data_opex_perday[$pl->id_opex][$i]);
                       $tengah .= <<<EOD
                     <td style="text-align: right" class="warna_harian">{$go_opex_perhari}</td>
EOD;
                     }
                     $go_opex = $this->form_eksternal->form_text_editable("opex_".$pl->id_opex, site_url("outlet/aktifitas/olah-editable-dinamis/opex/".$detail[0]->id_actifity_report."/{$pl->id_opex}"), number_format($data_opex_target[$pl->id_opex], 0, ",", "."), "callback : function(value, settings) {
              opex_lain();
              target_perday('opex_{$pl->id_opex}', 'target_perday_opex_{$pl->id_opex}');
            }", "", $privilege, $data_opex_target[$pl->id_opex]);
                      print <<<EOD
                  <tr>
                    <td colspan="2">{$pl->name}</td>
                    <td colspan="2" style="text-align: right" class="warna_target">{$go_opex}</td>
                    {$tengah}
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_opex_{$pl->id_opex}"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_opex_{$pl->id_opex}"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_opex_{$pl->id_opex}"></div></td>
                    <td style="border: 0; font-weight: bold">%</td>
                  </tr>
EOD;
                    }
                  }
                  ?>
                  <tr>
                    <th colspan="2">Total OPEX</th>
                    <td colspan="2" id="total_opex_lain" style="text-align: right; font-weight: bold"></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <th id="total_opex_perday_{$i}" style="text-align: right;"></th>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_opex"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_opex"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_opex"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #AAA">
                    <th colspan="2">MARGIN</th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="target_margin"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <th style="text-align: right"><div id="margin_{$i}"></div></th>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_margin"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_margin"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_margin"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #0F7">
                    <th colspan="<?=$detail[0]->day_in_month + 8?>">PENDAPATAN LAIN-LAIN</th>
                  </tr>
                  <?php
                  if(is_array($pendapatan_lain)){
                    foreach ($pendapatan_lain as $pl) {
                      $tengah = "";
                      for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                        $go_pendapatan_perhari = $this->form_eksternal->form_text_editable("pend_".$pl->id_pendapatan_lain."_".$i, site_url("outlet/aktifitas/olah-editable-dinamis/pendapatan_lain/".$detail[0]->id_actifity_report."/{$pl->id_pendapatan_lain}/{$i}"), number_format($data_pendapatan_lain_perday[$pl->id_pendapatan_lain][$i], 0, ",", "."), "callback : function(value, settings) {
              pendapatan_lain_perday({$i});
              realisasi('pend_{$pl->id_pendapatan_lain}', 'realisasi_pendapatan_{$pl->id_pendapatan_lain}');
              target_perday('pendapatan_{$pl->id_pendapatan_lain}', 'target_perday_pendapatan_{$pl->id_pendapatan_lain}');
              plus_day({$i});
            }", "", $privilege, $data_pendapatan_lain_perday[$pl->id_pendapatan_lain][$i]);
                       $tengah .= <<<EOD
                     <td style="text-align: right" class="warna_harian">{$go_pendapatan_perhari}</td>
EOD;
                     }
                     $go_pendapatan = $this->form_eksternal->form_text_editable("pendapatan_".$pl->id_pendapatan_lain, site_url("outlet/aktifitas/olah-editable-dinamis/pendapatan_lain/".$detail[0]->id_actifity_report."/{$pl->id_pendapatan_lain}"), number_format($data_pendapatan_lain_target[$pl->id_pendapatan_lain], 0, ",", "."), "callback : function(value, settings) {
              pendapatan_lain();
              target_perday('pendapatan_{$pl->id_pendapatan_lain}', 'target_perday_pendapatan_{$pl->id_pendapatan_lain}');
            }", "", $privilege, $data_pendapatan_lain_target[$pl->id_pendapatan_lain]);
              
                      print <<<EOD
                  <tr>
                    <td colspan="2">{$pl->name}</td>
                    <td colspan="2" style="text-align: right" class="warna_target">{$go_pendapatan}</td>
                    {$tengah}
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_pendapatan_{$pl->id_pendapatan_lain}"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_pendapatan_{$pl->id_pendapatan_lain}"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_pendapatan_{$pl->id_pendapatan_lain}"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
EOD;
                    }
                  }
                  ?>
                  <tr>
                    <th colspan="2">Total Pendapatan Lain-lain</th>
                    <td colspan="2" id="total_pendapatan_lain" style="text-align: right; font-weight: bold"></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <th id="total_pend_perday_{$i}" style="text-align: right; font-weight: bold"></th>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_total_pendapatan"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_total_pendapatan"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_total_pendapatan"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                  <tr style="background-color: #AAA">
                    <th colspan="2">LABA/RUGI </th>
                    <td colspan="2" style="text-align: right; font-weight: bold"><div id="target_laba_rugi"></div></td>
                    <?php
                    for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
                      print <<<EOD
                    <th style="text-align: right"><div id="laba_rugi_{$i}"></div></th>
EOD;
                    }
                    ?>
                    <td style="text-align: right; font-weight: bold"><div id="realisasi_laba_rugi"></div></td>
                    <td style="text-align: right; font-weight: bold"><div id="target_perday_laba_rugi"></div></td>
                    <td style="border: 0;text-align: right; font-weight: bold"><div id="achievement_laba_rugi"></div></td>
                    <td style="border: 0;font-weight: bold">%</td>
                  </tr>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
<?php
for($i = 1 ; $i <= $detail[0]->day_in_month ; $i++){
  print <<<EOD
    service_perday({$i});
    transaksi_perday({$i});
    service_perday({$i});
    belanja_perday({$i});
    transaksi_perday({$i});
    opex_perday({$i});
    pendapatan_lain_perday({$i});
    penerimaan_service_perday({$i});
    omset_perday({$i});
    rata_rupiah('p_service_{$i}', 'p_service_plus_{$i}','service_{$i}', 'service_belanja_{$i}', 'rata_service_{$i}');
    rata_rupiah('p_belanja_{$i}', 'p_belanja_plus_{$i}','belanja_{$i}', 'service_belanja_{$i}', 'rata_belanja_{$i}');
    gross_margin({$i});
    persentase_hpp('p_belanja_plus_{$i}', 'p_belanja_{$i}', 'total_hpp_{$i}', 'hpp_{$i}');
EOD;
}
?>
  total_unit_belanja();
  total_unit_entry_service();
  total_transaksi();
  pendapatan_lain();
  opex_lain();
  target_penerimaan_service();
  target_penerimaan_service_plus();
  target_penerimaan_belanja_plus();
  target_penerimaan_belanja();
  target_total_penerimaan();
  target_omset_transaksi();
  realisasi('service', 'realisasi_service');
  realisasi('service_belanja', 'realisasi_service_belanja');
  realisasi('belanja', 'realisasi_belanja');
  realisasi('total_service_perday', 'realisasi_total_service');
  realisasi('total_belanja_perday', 'realisasi_total_belanja');
  realisasi('total_transaksi_perday', 'realisasi_total_transaksi');
  target_perday('target_service', 'target_perday_service');
  target_perday('target_service_belanja', 'target_perday_service_belanja');
  target_perday('target_belanja', 'target_perday_belanja');
  target_perday('total_service', 'target_perday_total_service');
  target_perday('total_belanja', 'target_perday_total_belanja');
  target_perday('total_transaksi', 'target_perday_total_transaksi');
  
  realisasi('p_service', 'realisasi_p_service');
  realisasi('p_service_plus', 'realisasi_p_service_plus');
  realisasi('p_belanja_plus', 'realisasi_p_belanja_plus');
  realisasi('p_belanja', 'realisasi_p_belanja');
  realisasi('total_penerimaan_perday', 'realisasi_total_penerimaan_perday');
//  realisasi('total_omset_perday', 'realisasi_total_omset_perday');
  target_perday('target_penerimaan_service', 'target_perday_p_service');
  target_perday('target_penerimaan_service_plus', 'target_perday_p_service_plus');
  target_perday('target_penerimaan_belanja_plus', 'target_perday_p_belanja_plus');
  target_perday('target_penerimaan_belanja', 'target_perday_p_belanja');
  target_perday('target_total_penerimaan', 'target_perday_total_penerimaan');
//  target_perday('target_omset_transaksi', 'target_perday_total_omset');
  
//  realisasi('rata_service', 'realisasi_rata_service');
  rata_rupiah('realisasi_p_service', "realisasi_p_service_plus", 'realisasi_service', 'realisasi_service_belanja', 'realisasi_rata_service');
//  realisasi('rata_belanja', 'realisasi_rata_belanja');
  rata_rupiah('realisasi_p_belanja', "realisasi_p_belanja_plus", 'realisasi_belanja', 'realisasi_service_belanja', 'realisasi_rata_belanja');
//  target_perday('target_rata_service', 'target_perday_rata_service');
//  target_perday('target_rata_belanja', 'target_perday_rata_belanja');
  
  realisasi('total_opex_perday', 'realisasi_total_opex');
  target_perday('total_opex_lain', 'target_perday_total_opex');
  
  realisasi('total_pend_perday', 'realisasi_total_pendapatan');
  target_perday('total_pendapatan_lain', 'target_perday_total_pendapatan');
  
  realisasi('margin', 'realisasi_margin');
  target_perday('target_margin', 'target_perday_margin');
  
  realisasi('laba_rugi', 'realisasi_laba_rugi');
  target_perday('target_laba_rugi', 'target_perday_laba_rugi');
  
  
  realisasi('total_hpp', 'realisasi_total_hpp');
  target_perday('target_total_hpp', 'target_perday_total_hpp');
  
  realisasi('gross_margin', 'realisasi_gross_margin');
  target_perday('target_gross_margin', 'target_perday_gross_margin');
  
  omset_global('realisasi_total_transaksi', 'realisasi_total_penerimaan_perday', 'realisasi_total_omset_perday');
  
  omset_global('target_perday_total_transaksi', 'target_perday_total_penerimaan', 'target_perday_total_omset');
  persentase_hpp('realisasi_p_belanja_plus', 'realisasi_p_belanja', 'realisasi_total_hpp', 'realisasi_hpp');
  <?php
  if(is_array($opex)){
    $hasil_opex = "";
    foreach ($opex as $pl) {
      print "
        realisasi('opex_{$pl->id_opex}', 'realisasi_opex_{$pl->id_opex}');
        target_perday('opex_{$pl->id_opex}', 'target_perday_opex_{$pl->id_opex}');
        ";
    }
  }
  if(is_array($pendapatan_lain)){
    foreach ($pendapatan_lain as $pl) {
      print "
        realisasi('pend_{$pl->id_pendapatan_lain}', 'realisasi_pendapatan_{$pl->id_pendapatan_lain}');
        target_perday('pendapatan_{$pl->id_pendapatan_lain}', 'target_perday_pendapatan_{$pl->id_pendapatan_lain}');
        ";
    }
  }
  ?>
  
</script>